layui.define([ 'form', 'laydate', 'table','keyInformationApi'], function(exports) {
    var form = layui.form;
    var keyInformationApi = layui.keyInformationApi;
    var index = layui.index;
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                 form.on('submit(form)', function(){
                     /**
                      * 获取文件
                      */

                     var newDocumentsScanned = Common.fileRequire("#newDocumentsScannedDataList");
                     var oldDocumentsScanned = Common.fileRequire("#oldDocumentsScannedDataList");
                     if(newDocumentsScanned){
                         Common.alert("新的证件扫描件附件必须上传");
                     }else if(oldDocumentsScanned) {
                         Common.alert("旧的证件扫描件附件必须上传");
                     }else{
                             keyInformationApi.addKeyInformation($('#addForm'), function () {
                                 parent.window.dataReload();
                                 Common.info("添加成功");
                                 Lib.closeFrame();
                             });
                         }
                });
            });

            $("#addButton-PandD").click(function(){
                form.on('submit(form)', function(){
                        /**
                         * 获取文件
                         */

                        var newDocumentsScanned = Common.fileRequire("#newDocumentsScannedDataList");
                        var oldDocumentsScanned = Common.fileRequire("#oldDocumentsScannedDataList");
                        if(newDocumentsScanned){
                            Common.alert("新的证件扫描件附件必须上传");
                        }else if(oldDocumentsScanned) {
                            Common.alert("旧的证件扫描件附件必须上传");
                        }else {
                            Common.openConfirm("确认申报?", function () {
                            keyInformationApi.savedeclaration($('#addForm'),function(){
                            parent.window.dataReload();
                            Common.info("保存并申报成功");
                            Lib.closeFrame();
                    });},null);
                }
                });
            });
        
            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }
    			
    }
    exports('add',view);
});